//
//  JZHActivityViewController.m
//  极致荟
//
//  Created by mac on 14-4-8.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHActivityViewController.h"
#import "JZHPartyCell.h"
#import "JZHActivityViewController.h"
#import "SGActionView.h"
#import "JZHPublishActivityViewController.h"
#import "JZHCommentsViewViewController.h"
#import "JZHAuctionCell.h"
#import "JZHBlackCardCell.h"
#import "JZHBlackCardDetailViewController.h"
#import "JZHTabbarViewController.h"
#import "JZHHouViewController.h"
#import "JZHShare.h"
#import "JZHSHangPInViewController.h"
#import "JZHLisViewController.h"
#import "JZHDateViewController.h"
#import "JZHHowLookMeViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "JZHCityListViewController.h"
typedef NS_ENUM(NSInteger, MMCenterViewControllerSection){
    MMCenterViewControllerSectionLeftViewState,
    MMCenterViewControllerSectionLeftDrawerAnimation,
};

#pragma mark -
#pragma mark Private Interface
@interface JZHActivityViewController ()
{
    NSMutableArray *tableArray;
    NSMutableArray *pmArr;//拍卖数据列表
    JZHCEView *ce;
    //切换活动主题
    UIImageView *_navbarSelectView;
    UIView *cleraview;
    //current type
    NSInteger activityType; //0活动 1竞拍 3黑卡会
    
    NSNumber *partyType;//聚会类型
    int page;//页码
    NSNumber *partyCity;//城市ID
    NSMutableArray *myDataArr;//我的活动数据
    NSMutableArray *huDataArr;//会员活动数据
    NSString *imgPrefix;//图片地址前缀
    
  
}
@property (weak, nonatomic) IBOutlet UILabel *titlelable;

@property (weak, nonatomic) IBOutlet UIView *topview;



@end

#pragma mark -
#pragma mark Implementation
@implementation JZHActivityViewController
UIButton *leftButton;
- (id)init
{
    self = [super init];
    if (self) {
        [self setRestorationIdentifier:@"MMExampleCenterControllerRestorationKey"];
    }
    return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [leftButton setSelected:NO];
    [ce remove];
    [ce right];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[JZHTabbarViewController shareInstance] showTabBar2];
    
    NSArray *arr=[[NSArray alloc]initWithObjects:@"城市",@"品鉴",@"高尔夫",@"盛宴",@"会议",@"旅游",@"电影",@"课程", nil];
    ce= [[JZHCEView alloc]initarr:arr viewConetroller:[JZHTabbarViewController shareInstance]TopviewStype:2];
    ///侧边栏回调
    __block UIViewController *controller=self;
    ce.pusblock=^(int i){
        if(i!=0)
        {
            partyType=[NSNumber numberWithInt:i];
            [myDataArr removeAllObjects];
            page=1;
            [self loadMyPartyHttpDataPage:page showHUD:YES keyword:@""];
        }else
        {
            [UINavigationController Pus:self ToViewconeroller:[[JZHCityListViewController alloc]initController:self]];
        }
        [ce right];
        
    };
    
    ce.alldata=^(){
        page=1;
        [myDataArr removeAllObjects];
        partyType=[NSNumber numberWithInt:0];
        [self loadMyPartyHttpDataPage:page showHUD:YES keyword:@""];
    };
    ce.rection=^(int i){
        if(i==1)
        {
            leftButton.selected=YES;
        }else
        {
            leftButton.selected=NO;
        }
    };
    [ce setCeDelete:self];
    if(activityType!=0)
    {
        [ce panGesturUserEnable:NO];
    }
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self showHiedr];
    [self.activityTableView setPullDelegate:self];
    //1.注册重用 Cell
    //  1.1注册活动cell
    [self.activityTableView registerClass:[JZHPartyCell class] forCellReuseIdentifier:@"activityPartyCell"];
    //  1.2注册竞拍cell
    [self.activityTableView registerClass:[JZHAuctionCell class] forCellReuseIdentifier:@"auctionCell"];
    //  1.3注册黑卡会cell
    [self.activityTableView registerClass:[JZHBlackCardCell class] forCellReuseIdentifier:@"blackCardCell"];
    
    //2设置导航
    [self setNavigation];
    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
    
    myDataArr=[[NSMutableArray alloc]init];
    huDataArr=[[NSMutableArray alloc]init];
    pmArr=[[NSMutableArray alloc]init];
    partyCity=[NSNumber numberWithInt:[[[User defuceUser].citydic objectForKey:@"id"] intValue]];
    partyType=[NSNumber numberWithInt:0];
    page=1;
    [self loadMyPartyHttpDataPage:page showHUD:YES keyword:@""];
    

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark ---导航----
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//导航条设置
-(void)setNavigation
{
    
    //设置导航视图title
    
    self.navigationItem.titleView = _titleView;
    [_popoverBg setImage:[[UIImage imageNamed:@"popover_background.png"]stretchableImageWithLeftCapWidth:10 topCapHeight:30]];
    
    [_popoverView setCenter:CGPointMake(150, 140)];
    
    
    //设置右侧导航按钮
    UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 42, 44)];
    [rightButton setTitle:@"发活动" forState:UIControlStateNormal];
    [rightButton setTitle:@"发活动" forState:UIControlStateHighlighted];
    rightButton.titleLabel.textAlignment=UITextAlignmentRight;
    [rightButton addTarget:self action:@selector(rightBarButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    //[rightButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 100)];
    rightButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    [rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    
    self.navigationItem.rightBarButtonItem = rightBarButton;
    //设置左侧按钮
    leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"leftbar_item_bg.png"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
}
//返回
-(void)back:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark --UITableViewDataSource methods-
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (activityType == 0) {
        return myDataArr.count;
    }else if (activityType == 1 && pmArr){
        return pmArr.count;
       
    }else if (activityType == 2){
        return huDataArr.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (activityType == 0) {
        JZHPartyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"activityPartyCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.pusshare=^(){
            JZHShare *share=[[NSBundle mainBundle]loadNibNamed:@"JZHShare" owner:self options:nil][0];
            [share show:1 viewcontroller:self];
            return share;
            };
       
        cell.controller=self;
        if(myDataArr.count!=0)
        {
         [cell adddata:myDataArr[indexPath.row] headpath:imgPrefix];
        }
  
        return cell;
    }else if (activityType == 1){
        JZHAuctionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"auctionCell" forIndexPath:indexPath];
        //---------------------------------
        JZHCommodity *comm=[[JZHCommodity alloc]initId:[[[pmArr objectAtIndex:indexPath.row]objectForKey:@"id"] floatValue]Name:[[pmArr objectAtIndex:indexPath.row]objectForKey:@"name"] Price:0 ImageArr:nil Content:nil];
        comm.paprice=[[[pmArr objectAtIndex:indexPath.row]objectForKey:@"price"] floatValue];
        comm.surplustime=[[[pmArr objectAtIndex:indexPath.row]objectForKey:@"remainingTime"] longValue];
        [cell adddata:comm];
         //---------------------------------
        [self gundong:cell];
        return cell;
    }else if (activityType == 2){
        JZHBlackCardCell *cell = [tableView dequeueReusableCellWithIdentifier:@"blackCardCell" forIndexPath:indexPath];
        [cell addclldata:[huDataArr objectAtIndex:indexPath.row]];
        return cell;
    }
    return nil;
}

///竞拍商品名滚动
- (void)gundong:(JZHAuctionCell *)cell
{
    
    [cell.spname sizeToFit];
    
    NSLog(@"%f",cell.spname.frame.size.width);
    [cell.spscroll setContentSize:CGSizeMake(cell.spname.frame.size.width+90, 0)];
    if(!cell.timerun)
    {
        NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerFired:) userInfo:[[NSDictionary alloc]initWithObjectsAndKeys:cell,@"cell", nil] repeats:YES];
        cell.timerun=YES;
    }
    
}

- (void)timerFired:(NSTimer *)time
{
    JZHAuctionCell *cell=[time.userInfo objectForKey:@"cell"];
    [cell.spscroll setContentOffset:CGPointMake(cell.spscroll.contentOffset.x+2, 0)];
   // NSLog(@"%f~~~~%f",cell.spscroll.contentSize.width,cell.spscroll.contentOffset.x);
    if(cell.spscroll.contentOffset.x>cell.spscroll.contentSize.width)
    {
        [cell.spscroll setContentOffset:CGPointMake(0, 0)];
    }
}
#pragma mark --UITableViewDelegate methods-
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"%d",activityType);
    JZHAuctionCell *cell=(JZHAuctionCell *)[tableView cellForRowAtIndexPath:indexPath];

    if (activityType == 0) {
        
    }else if (activityType == 1){
        
        [UINavigationController Pus:self ToViewconeroller:[[JZHSHangPInViewController alloc]initCommodity:cell.comm]];
        
    }else if (activityType == 2){
                JZHBlackCardDetailViewController *blackCardDetail = [[JZHBlackCardDetailViewController alloc] initCommodity: huDataArr[indexPath.row]];
         [UINavigationController Pus:self ToViewconeroller:blackCardDetail];
    

        
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (activityType == 0) {
        return 383;
    }else if (activityType == 1){
        return 190;
    }else if (activityType == 2){
        return 106;
    }
    return 0;
}

#pragma mark - PullTableViewDelegate

- (void)pullTableViewDidTriggerRefresh:(PullTableView *)pullTableView
{
    [self refreshTable];
}

- (void)pullTableViewDidTriggerLoadMore:(PullTableView *)pullTableView
{
    [self loadMoreDataToTable];
}
#pragma mark - Refresh and load more methods

///TableView刷新
- (void) refreshTable
{
    page=1;
    if(activityType==0)
    {
        [myDataArr removeAllObjects];
        [self loadMyPartyHttpDataPage:page showHUD:NO keyword:@""];
    }
    
    if(activityType==1)
    {
        [pmArr removeAllObjects];
        [self loadPaHttpDataPage:page showHUD:NO];
    }
    if(activityType==2)
    {
        [huDataArr removeAllObjects];
        [self loadHoHttpDataPage:page showHUD:NO clubdate:@"" isHistory:0];
    }
    self.activityTableView.pullLastRefreshDate = [NSDate date];
   
    
}

///TableView加载更多
- (void) loadMoreDataToTable
{
    page++;
    if(activityType==0)
    {
        
        [self loadMyPartyHttpDataPage:page showHUD:NO keyword:@""];
    }
    
    if(activityType==1)
    {
        [self loadPaHttpDataPage:page showHUD:NO];
    }
    if(activityType==2)
    {
         [self loadHoHttpDataPage:page showHUD:NO clubdate:@"" isHistory:0];
    }
    self.activityTableView.pullLastRefreshDate = [NSDate date];
}

///当在城市列表中选取城市数据时，由城市列表对象调用，本类中不调用
- (void)partycityId:(NSNumber*)number
{
    partyCity=number;
    page=1;
    partyType=[NSNumber numberWithInt:0];
    [myDataArr removeAllObjects];
    [self loadMyPartyHttpDataPage:page showHUD:YES keyword:@""];
    
}

///当在日历中选取数据时，由日历对象调用，本类中不调用
- (void)hudatestr:(NSString *)datestr
{
    page=1;
    //NSLog(@"%@",datestr);
    [huDataArr removeAllObjects];
    [self loadHoHttpDataPage:page showHUD:YES clubdate:datestr isHistory:0];
}

#pragma mark-------侧边栏代理------
- (void)CESo:(NSString *)str
{
    page=1;
    partyCity=[NSNumber numberWithInt:0];
    [myDataArr removeAllObjects];
    partyType =[NSNumber numberWithInt:0];
    [self loadMyPartyHttpDataPage:page showHUD:YES keyword:str];

}
#pragma mark----------网络请求--------------
///加载我的活动数据列表
- (void)loadMyPartyHttpDataPage:(int)i showHUD:(BOOL)isend keyword:(NSString *)keyword
{
    
   if(isend)
   {
       //[MMProgressHUD showWithStatus:@"数据加载中..."];
   }
    
   // NSLog(@"%d  %d  %d",partyType.intValue,[[[User defuceUser].citydic objectForKey:@"id"] intValue],i);
    NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:partyType,@"partyType",partyCity,@"cityId",[NSNumber numberWithInt:i],@"page", keyword,@"keyword",[NSNumber numberWithInt:[User defuceUser].userId],@"userId",nil];
   
   // NSLog(@"%@",dic);
    [HttpRequest httpRequestPost:JZHHTTPURL(@"party/partyList") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        
        if(rerurncode==0)
        {
            [MMProgressHUD dismiss];
            NSLog(@"%@",data);
            
            imgPrefix=[[data objectForKey:@"data"] objectForKey:@"imgPrefix"];
            NSArray *arr=[[data objectForKey:@"data"] objectForKey:@"list"];
            for(NSDictionary *datadic in arr)
            {
                //创建活动实体类
                JZHActivities *jzh=[[JZHActivities alloc]init];
                //创建其他用户实体lei
                OtherUsers *ouser=[[OtherUsers alloc]init];
                ouser.userId=[[datadic objectForKey:@"userId"] intValue];
                ouser.userHeadImage=[imgPrefix stringByAppendingString:[datadic objectForKey:@"avatar"]];
                ouser.name=[datadic objectForKey:@"userName"];
                
                jzh.actId=[[datadic objectForKey:@"id"] intValue];
                jzh.addes=[datadic objectForKey:@"address"];
                jzh.actdate=[[NSDate alloc]initWithTimeIntervalSince1970:[[datadic objectForKey:@"partyTime"] longLongValue]];
                jzh.actType=[[datadic objectForKey:@"partyCate"] intValue];
                jzh.max=[[datadic objectForKey:@"people"] intValue];
                jzh.consumptionMode=[[datadic objectForKey:@"payment"] intValue];
                jzh.acttile=[datadic objectForKey:@"subject"];
                jzh.content=[datadic objectForKey:@"detail"];
                jzh.actimages=[datadic objectForKey:@"partyImage"];
                jzh.isjoin=[[datadic objectForKey:@"joinStatus"] boolValue];
                jzh.mainuser=ouser;
                NSMutableArray *userarr=[[NSMutableArray alloc]init];
                for(NSDictionary *userdic in [datadic objectForKey:@"joinList"])
                {
                    [userarr addObject:[userdic objectForKey:@"userAvatar"]];
                }
                jzh.userarr=userarr;
               // NSLog(@"%@",jzh.actdate);
                [myDataArr addObject:jzh];
               
            }
          
        }else
        {
            [MMProgressHUD showInformationWithTips:@"暂无数据"];
        }
         [self.activityTableView setPullTableIsRefreshing:NO];
        [self.activityTableView setPullTableIsLoadingMore:NO];
          [self.activityTableView reloadData];
    }];
}

///加载拍卖网络数据
- (void)loadPaHttpDataPage:(int)i showHUD:(BOOL)isend
{
 
    if(isend)
    {
    //[MMProgressHUD showWithStatus:@"数据加载中..."];
    }
    
    NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:i],@"page" ,nil];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"auction/init") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        if(rerurncode==0)
        {
            NSLog(@"%@",data);
            for(NSDictionary *dicda in [data objectForKey:@"data"])
            {
                [pmArr addObject:dicda];
            }
           [self.activityTableView reloadData];
            [MMProgressHUD dismiss];
            self.titlelable.text=@"竞拍专题";
            [[self.navigationItem.rightBarButtonItem customView] setHidden:YES];
            [[self.navigationItem.leftBarButtonItem customView] setHidden:YES];
            [ce panGesturUserEnable:NO];
        }else
        {
           [MMProgressHUD showInformationWithTips:@"暂无数据"];
        }
        [self.activityTableView setPullTableIsRefreshing:NO];
        [self.activityTableView setPullTableIsLoadingMore:NO];
        [self.activityTableView reloadData];
    }];
}

///加载活动数据
- (void)loadHoHttpDataPage:(int)i showHUD:(BOOL)isend clubdate:(NSString *)date isHistory:(int) ishis
{
    if(isend)
    {
       // [MMProgressHUD showWithStatus:@"数据加载中..."];
    }
    NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:date,@"clubDate",[NSNumber numberWithInt:i],@"page",[NSNumber numberWithInt:ishis],@"isHistory", nil];

    [HttpRequest httpRequestPost:JZHHTTPURL(@"club/clubList") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        
        if(rerurncode==0)
        {
            [MMProgressHUD dismiss];
            NSLog(@"%@",data);
            imgPrefix=[[data objectForKey:@"data"] objectForKey:@"imgPrefix"];
            NSArray *arr=[[data objectForKey:@"data"] objectForKey:@"list"];
            for(NSDictionary *datadic in arr)
            {
                //创建活动实体类
                JZHActivities *jzh=[[JZHActivities alloc]init];
                jzh.actdate=[NSDate dateWithTimeIntervalSince1970:[[datadic objectForKey:@"clubTime"]longLongValue]];
                jzh.actId=[[datadic objectForKey:@"id"] intValue];
                jzh.acttile=[datadic objectForKey:@"subject"];
                jzh.actimage=[imgPrefix stringByAppendingString:[datadic objectForKey:@"coverImg"]];
                jzh.cityname=[datadic objectForKey:@"cityName"];
                [huDataArr addObject:jzh];
                [MMProgressHUD dismiss];
            }
            
        }else
        {
          [MMProgressHUD showInformationWithTips:@"暂无数据"];
        }
        [self.activityTableView setPullTableIsRefreshing:NO];
        [self.activityTableView setPullTableIsLoadingMore:NO];
        [self.activityTableView reloadData];
    }];

}
-(void)contentSizeDidChange:(NSString *)size{
    [self.activityTableView reloadData];
}

#pragma mark - Button Handlers

- (void)leftDrawerButtonPress:(UIButton *)sender
{
    if(!sender.selected)
    {
        [ce left];
        sender.selected=YES;
        
    }else
    {
        [ce right];
        sender.selected=NO;
        
    }
}

-(void)rightBarButtonPress:(id)sender
{
    [self  titleViewAnimation];
    JZHShare *share=[[NSBundle mainBundle]loadNibNamed:@"JZHShare" owner:self options:nil][0];
    [share show:2 viewcontroller:self];
}

-(void)doubleTap:(UITapGestureRecognizer*)gesture{
    
}

-(void)twoFingerDoubleTap:(UITapGestureRecognizer*)gesture{
    
}

#pragma mark --切换其他－



- (IBAction)dropDown:(UIButton *)sender {
    //旋转三角尖
    if ([sender isSelected]) {
        
        [sender setSelected:NO];
        CABasicAnimation *spinAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        [spinAnimation setFromValue:[NSNumber numberWithFloat:-M_PI]];
        [spinAnimation setToValue:[NSNumber numberWithDouble:0]];
        [spinAnimation setDelegate:self];
        [spinAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [spinAnimation setDuration:0.5];
        [_titleArrow.layer addAnimation:spinAnimation forKey:@"spin"];
        [_titleArrow.layer setTransform:CATransform3DMakeRotation(0, 0, 0, 1)];
    }else{
        [sender setSelected:YES];
        CABasicAnimation *spinAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        [spinAnimation setFromValue:[NSNumber numberWithFloat:0]];
        [spinAnimation setToValue:[NSNumber numberWithDouble:-M_PI]];
        [spinAnimation setDelegate:self];
        [spinAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
        [spinAnimation setDuration:0.3];
        [_titleArrow.layer addAnimation:spinAnimation forKey:@"spin"];
        [_titleArrow.layer setTransform:CATransform3DMakeRotation(-M_PI, 0, 0, 1)];
    }
    
    //弹出下拉菜单
    if (_popoverView.superview == self.navigationController.view) {
        CATransition *animation = [CATransition  animation];
        animation.delegate = self;
        animation.duration = 0.3;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.type = kCATransitionPush;
        animation.subtype = kCATransitionFromTop;
        [_popoverView setAlpha:0.0f];
        [_popoverView.layer addAnimation:animation forKey:@"DropDown"];
        [_popoverView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.3];
       
        [cleraview setHidden:YES];
    }else
    {
        CATransition *animation = [CATransition  animation];
        animation.delegate = self;
        animation.duration = 0.3;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.type = kCATransitionPush;
        animation.subtype = kCATransitionFromBottom;
        [_popoverView setAlpha:1.0f];
        [_popoverView.layer addAnimation:animation forKey:@"DropDown"];
        if(cleraview)
        {
            [cleraview setHidden:NO];
        }else
        {
            cleraview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
            [self.view addSubview:cleraview];
        }
        
        [self.navigationController.view addSubview:_popoverView];
    }
}


#pragma mark --动画title view
- (void)titleViewAnimation{
    [self dropDown:_titleTapButton];
        [_titleTapButton setSelected:NO];
    
    
    
    
    //弹出下拉菜单
    if (_popoverView.superview == self.navigationController.view) {
        CATransition *animation = [CATransition  animation];
        animation.delegate = self;
        animation.duration = 0.3;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.type = kCATransitionPush;
        animation.subtype = kCATransitionFromTop;
        [_popoverView setAlpha:0.0f];
        [_popoverView.layer addAnimation:animation forKey:@"DropDown"];
        [_popoverView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.3];
        [cleraview setHidden:YES];
    }else
    {
        CATransition *animation = [CATransition  animation];
        animation.delegate = self;
        animation.duration = 0.3;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.type = kCATransitionPush;
        animation.subtype = kCATransitionFromBottom;
        [_popoverView setAlpha:1.0f];
        [_popoverView.layer addAnimation:animation forKey:@"DropDown"];
        [cleraview setHidden:NO];
        
        [self.navigationController.view addSubview:_popoverView];
    }
}
- (IBAction)jingPaiAction:(UIButton *)sender {
    
    
    [self  titleViewAnimation];
    activityType = 1;
    if(!sender.selected)
    {
        [self showHiedr];
        sender.selected=YES;
        UIButton *but=(UIButton *)[_popoverView viewWithTag:301];
        but.selected=NO;
        but=(UIButton *)[_popoverView viewWithTag:303];
        but.selected=NO;
        page=1;
        //[self.activityTableView reloadData];
        if(pmArr.count<1)
        {
        [self loadPaHttpDataPage:1 showHUD:YES];
        }else
        {
            [self.activityTableView reloadData];
        }
        
        NSLog(@"竞拍数据");
        
    }
}

- (IBAction)heikahuiAction:(UIButton *)sender {

    [self  titleViewAnimation];
    activityType = 2;
    if(!sender.selected)
    {
        [self showHiedr];
        sender.selected=YES;
        [self.activityTableView reloadData];
          NSLog(@"会员活动");
        page=1;
        UIButton *but=(UIButton *)[_popoverView viewWithTag:301];
        but.selected=NO;
        but=(UIButton *)[_popoverView viewWithTag:302];
        but.selected=NO;
        self.titlelable.text=@"会员活动";
        [[self.navigationItem.rightBarButtonItem customView] setHidden:YES];
        [[self.navigationItem.leftBarButtonItem customView] setHidden:YES];
        [ce panGesturUserEnable:NO];
        
        if(huDataArr.count<1)
        {
            [huDataArr removeAllObjects];
          [self loadHoHttpDataPage:page showHUD:YES clubdate:@"" isHistory:0];
        }else
        {
              [self.activityTableView reloadData];
        }
        
        
    }

}


- (IBAction)juhuiAction:(UIButton *)sender {
    
    
    [self  titleViewAnimation];
    activityType = 0;
    if(!sender.selected)
    {
        [self showHiedr];
        sender.selected=YES;
        UIButton *but=(UIButton *)[_popoverView viewWithTag:302];
        but.selected=NO;
        but=(UIButton *)[_popoverView viewWithTag:303];
        but.selected=NO;
        page=1;
        [self.activityTableView reloadData];
        
       self.titlelable.text=@"我的活动";
        [[self.navigationItem.rightBarButtonItem customView] setHidden:NO];
        [[self.navigationItem.leftBarButtonItem customView] setHidden:NO];
        [ce panGesturUserEnable:YES];
    }

}

//是否显示头部VIEW
- (void)showHiedr
{
    if(activityType==2)
    {
        self.topview.hidden=NO;
        [UIView animateWithDuration:0.1 animations:^{
             [self.activityTableView setFrame:CGRectMake(0, self.topview.frame.origin.y+self.topview.frame.size.height, self.activityTableView.frame.size.width, self.activityTableView.frame.size.height)];
        }];
       
    }else
    {
        self.topview.hidden=YES;
        [UIView animateWithDuration:0.1 animations:^{
            [self.activityTableView setFrame:CGRectMake(0, self.topview.frame.origin.y, self.activityTableView.frame.size.width, self.activityTableView.frame.size.height)];
        }];
 
    }
}
- (IBAction)pusdate:(id)sender
{
    [UINavigationController Pus:self ToViewconeroller:[[JZHDateViewController alloc]initViewController:self]];
}
- (IBAction)pusLIshi:(id)sender
{
    [UINavigationController Pus:self ToViewconeroller:[[JZHLisViewController alloc]init] ];
}
@end
